<template>
	<view class="container">
		<!-- 顶部选项卡 -->
		<view class="swiper-tab dis-flex flex-x-around flex-y-center">
			<view v-for="(item, index) in tabList" :key="index" :class="{ on: dataType == item.value }" class="swiper-tab-item " :data-current="item.value" @tap.stop="swichNav">{{ item.text }}</view>
		</view>
		<!-- 退款/售后单 -->
		<scroll-view :scroll-y="true" @scrolltolower="triggerDownLoad" :style="{ height: swiperHeight + 'px' }">
			<view class="widget-list" v-if="list.data.length">
				<view class="widget-detail" v-for="(item, index) in list.data" :key="index" @tap="triggerDetail" :data-id="item.order_refund_id">
					<view class="row-block dis-flex flex-y-center">
						<view class="flex-box">{{ item.create_time }}</view>
						<view class="flex-box t-r">
							<text class="col-m">{{ item.state_text }}</text>
						</view>
					</view>
					<view class="detail-goods row-block dis-flex">
						<view class="goods-image"><image :src="item.order_goods.image.file_path" mode="aspectFit"></image></view>
						<view class="goods-right flex-box">
							<view class="goods-name">
								<text class="twolist-hidden">{{ item.order_goods.goods_name }}</text>
							</view>
							<view class="goods-attr">
								<text class="f-26 col-8">{{ item.order_goods.goods_attr }}</text>
							</view>
							<view class="goods-num t-r">
								<text class="f-26 col-8">×{{ item.order_goods.total_num }}</text>
							</view>
						</view>
					</view>
					<view class="detail-order row-block dis-flex flex-x-end flex-y-center">
						<text class="">付款金额：</text>
						<text class="col-m">￥{{ item.order_goods.total_pay_price }}</text>
					</view>
					<view class="detail-operate row-block dis-flex flex-x-end flex-y-center"><view class="detail-btn btn-detail" @tap.stop="triggerDetail" :data-id="item.order_refund_id">查看详情</view></view>
				</view>
				<!-- 没有更多 -->
				<view v-if="list.data.length && !isLoading && no_more" class="no-more f-30">亲, 没有更多了</view>
			</view>
			<!-- 没有记录 -->
			<view class="yoshop-notcont" v-if="!list.data.length && !isLoading">
				<text class="iconfont icon-wushuju"></text>
				<text class="cont">亲，暂无退款/售后单哦</text>
			</view>
		</scroll-view>
	</view>
</template>

<script>
import Route from '@/utils/Route.js';
export default {
	data() {
		return {
			applyStatus: [],
			isLoading: true,
			dataType: -1,
			page: 1,
			no_more: false,
			swiperHeight: null,
			tabList: [],
			list: { data: [] }
		};
	},
	onLoad() {
		this.setSwiperHeight();
	},
	onShow() {
		this.getRefundList();
	},
	methods: {
		/**
		 * 获取退款/售后单列表
		 */
		getRefundList(isNextPage, page) {
			this.$get(this.$api.getSharingRefundLists, { state: this.dataType, page: page || 1 }, res => {
				const data = this.createData(res.data, isNextPage);
				this.isLoading = data.isLoading;
				this.list = data.list;
				this.tabList = data.tabList;
			});
		},
		/**
		 * 创建页面数据
		 */
		createData(data, isNextPage) {
			data['isLoading'] = false;
			// 列表数据
			let dataList = this.list;
			if (isNextPage == true && typeof dataList !== 'undefined') {
				data.list.data = dataList.data.concat(data.list.data);
			}
			// 导航栏数据
			data['tabList'] = [
				{
					value: -1,
					text: '全部'
				},
				{
					value: 0,
					text: '待处理'
				}
			];
			return data;
		},
		/**
		 * 设置swiper的高度
		 */
		setSwiperHeight() {
			// 获取系统信息(拿到屏幕宽度)
			let systemInfo = uni.getSystemInfoSync();
			let tapHeight = uni.upx2px(82); // tap高度
			this.swiperHeight = systemInfo.windowHeight - tapHeight; // swiper高度
		},
		/**
		 * 点击tab切换
		 */
		swichNav(e) {
			let current = e.currentTarget.dataset.current;
			if (this.dataType == current) {
				return false;
			}
			this.dataType = current;
			this.list = { data: [] };
			this.page = 1;
			this.no_more = false;
			this.isLoading = true;
			this.$nextTick(() => {
				this.getRefundList();
			});
		},

		/**
		 * 下拉到底加载数据
		 */
		triggerDownLoad() {
			// 已经是最后一页
			if (this.page >= this.list.last_page) {
				this.no_more = true;
				return false;
			}
			// 获取退款/售后单列表
			this.getRefundList(true, ++this.page);
		},
		/**
		 * 跳转售后详情页
		 */
		triggerDetail(e) {
			Route.navigateTo({
				url: './detail/detail?order_refund_id=' + e.currentTarget.dataset.id
			});
		}
	}
};
</script>

<style>
.container {
	font-size: 28rpx;
	color: rgb(90, 90, 90);
}

/* 选项卡 */

.swiper-tab {
	width: 100%;
	text-align: center;
	height: 80rpx;
	background-color: #fff;
	border-bottom: 1px solid #eee;
}

.swiper-tab .swiper-tab-item {
	width: 160rpx;
	height: 100%;
	color: #777;
	display: flex;
	justify-content: center;
	align-items: center;
	box-sizing: border-box;
	border-bottom: 2px solid #ffffff00;
}

.swiper-tab .on {
	color: #ff495e;
	border-bottom: 2px solid #ff495e;
}

/* 设置scroll-view容器高度 */

.widget-list,
.yoshop-notcont {
	height: 100.1%;
}

/* 数据列表 */

.widget-list {
	/* padding: 0 20rpx 40rpx 20rpx; */
	padding-bottom: 40rpx;
	box-sizing: border-box;
}

.widget-detail {
	box-sizing: border-box;
	border-bottom: 1rpx solid #e7e7e7;
	background: #fff;
	margin-bottom: 20rpx;
}

.widget-detail .row-block {
	padding: 0 20rpx;
	min-height: 70rpx;
}

.widget-detail .detail-goods {
	padding: 20rpx;
	background: #fbfbfb;
}

.widget-detail .detail-goods .goods-image {
	margin-right: 20rpx;
}

.widget-detail .detail-goods .goods-image image {
	display: block;
	width: 200rpx;
	height: 200rpx;
}

.widget-detail .detail-goods .goods-right {
	padding: 15rpx 0;
}

.widget-detail .detail-goods .goods-name {
	margin-bottom: 10rpx;
}

.widget-detail .detail-goods .goods-attr {
	min-height: 32rpx;
}

.widget-detail .detail-operate {
	border-top: 1px solid rgb(241, 241, 241);
	padding-top: 10rpx;
	padding-bottom: 10rpx;
}

.widget-detail .detail-operate .detail-btn {
	border-radius: 4px;
	border: 1rpx solid #ccc;
	padding: 8rpx 20rpx;
	font-size: 28rpx;
	color: #555;
	margin-left: 10rpx;
}
</style>
